#include "CmdWorker.h"
//#include <windows.h>

CmdWorker::CmdWorker(void)
{
}


CmdWorker::~CmdWorker(void)
{
}

void CmdWorker::cmdprocess( OS_TcpSocket tcc, header hd )
{
	switch (hd.cmd)
	{
	case HT_HELLO:
	{
	    const char* str = "HELLO TO YOU...VER 1.0";
	    tcc.Send(str,strlen(str));
	}
	//break;
	case HT_GET_LIST:
	{
	    char buff[4096];
	    int len = 0;
	    FILE* fp = popen("ls -l", "rb");
	    
	    if (!fp) 
	    {
		perror("ls");
		break;
	    }
	    while(1)
	    {
		len = fread(buff, 1,4096, fp);
		if (len <= 0 )break;
		tcc.Send(buff, len);
	    }
	}
	break;
	case HT_OVER:
	    break;
	case HT_UPLOAD:
	    break;
	case HT_CMD:
	{
	    char buff[4096];
	    int len = 0;
	    FILE* fp = popen("ls -l", "rb");
	    
	    if (!fp) 
	    {
		perror("ls");
		break;
	    }
	    while(1)
	    {
		len = fread(buff, 1,4096, fp);
		if (len <= 0 )break;
		tcc.Send(buff, len);
	    }
	}
	break;
	default:
	    break;
	}
}
